<?php
declare (strict_types=1);

namespace app\api\controller\v1;

use app\common\model\Datum;

class SendSpell extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return sucessMsg(200, '获取成功', [
            'neirong' => $this->cont(),   //获取学习中心-短句拼写
        ]);
    }

    /**
     * 获取短句拼写内容
     *
     * @return \think\Response
     */
    public function cont()
    {
        $page = input('page/d', 1);
        $pageSize = input('pageSize/d', 1);
        $model = new Datum();
        $grade_id = input('grade_id/d');
        $unit_id = input('unit_id/d');
        $mold_id = input('mold_id/d', 3);
        $course_id = input('course_id/d', 2);
        $where = [
            'status' => 1,
            'grade_id' => $grade_id,
            'unit_id' => $unit_id,
            'course_id' => $course_id,
            'mold_id' => $mold_id,
        ];
        $data = $model->where($where)->page($page, $pageSize)->find()->toArray();
        $rows = count($model->where($where)->select()->toArray());
        $maxPage = ceil($rows / $pageSize);
        return ['data' => $data, 'total' => $rows, 'maxPage' => $maxPage];
    }
}
